package com.yjt.fresh.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.willy.ratingbar.ScaleRatingBar;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.HttpManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.R;
import com.yjt.fresh.api.ApiGetCommentDetail;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.bean.BeanCommentDetail;
import com.yjt.fresh.bean.BeanUserComment;
import com.yjt.fresh.constant.MyConstants;
import com.yjt.fresh.utils.PreferenceManager;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 评论详情
 * Created by mcc on 2018/8/2.
 */

public class AtyCommentDetail extends BaseSimpleActivity {
    @BindView(R.id.back)
    RelativeLayout mBack;
    @BindView(R.id.ivAppAtyCommentDetail)
    ImageView mIv;
    @BindView(R.id.ratingBarAppAtyCommentDetail)
    ScaleRatingBar mRatingBar;
    @BindView(R.id.tvAppAtyCommentDetailContent)
    TextView mTvContent;
    @BindView(R.id.tvAppAtyCommentDetailTime)
    TextView mTvTime;
    private BeanUserComment.BeanUserCommentInfo mCommentInfo;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_comment_detail;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initEvent() {
        mCommentInfo = (BeanUserComment.BeanUserCommentInfo) getIntent().getSerializableExtra(MyConstants.COMMENT_BEAN);
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        getData();
    }

    HttpOnNextListener<BeanCommentDetail> mDetailListener = new HttpOnNextListener<BeanCommentDetail>() {
        @Override
        public void onNext(BeanCommentDetail beanCommentDetail) {
            Glide.with(mContext).load(beanCommentDetail.getSKU_IMG()).into(mIv);
            mRatingBar.setRating(Integer.valueOf(beanCommentDetail.getEVALUATE_GRADE()));
            mTvContent.setText(beanCommentDetail.getEVALUATE_CONTENT());
            mTvTime.setText(beanCommentDetail.getCREATE_TIME());
        }

        @Override
        public void onReLogin() {
            toLogin();
        }
    };
    private void getData() {
        ApiGetCommentDetail apiGetCommentDetail = new ApiGetCommentDetail(mDetailListener,mContext,true,false,false);
        Map<String,Object> map = new HashMap<>();
        map.put("SESSION_ID", PreferenceManager.getInstance().getUserInfo().getSESSION_ID());
        map.put("ORDERSITEM_ID",mCommentInfo.getORDERSITEM_ID());
        apiGetCommentDetail.setMap(map);
        HttpManager.getInstance().doHttpDeal(apiGetCommentDetail);
    }


}
